﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.Model;
using System.Data;
using HZ.Supervise.IBLL;


namespace HZ.Supervise.Web.Secondphase.NewReport
{
    public partial class SunScoreHospitalPut : BasePage
    {
        HZ.Supervise.IBLL.IExecuteContext i = HZ.Supervise.BLLFactory.ExecuteContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                hfhospitalid.Value = Request.QueryString["HospitalID"];
                BindData();
            }
        }

        private void BindData()
        {
            this.lblHospitalName.Text = HZ.Data.DbHelperFactory.Create().ExecuteScalar(string.Format(@"select HospitalName from TB_Hospital where HospitalID='{0}'", hfhospitalid.Value)).ToString();
            this.lblTime.Text = DateTime.Now.ToShortDateString();

            int year = DateTime.Now.Year;
            int month = 0;
            if (DateTime.Now.Day > 10)
            {
                month = DateTime.Now.Month;
            }
            else if (DateTime.Now.Month - 1 == 0)
            {
                month = 12;
                year = DateTime.Now.Year - 1;
            }
            else
            {
                month = DateTime.Now.Month - 1;
            }
            DataTable dt = i.GetSunScoreByHospital(hfhospitalid.Value, year, month);
            if (dt.Rows.Count > 0)
            {
                ddlIsShiGu.SelectedValue = dt.Rows[0]["IsShiGu"].ToString();
                ddlIsPeiHe.SelectedValue = dt.Rows[0]["IsPeiHe"].ToString();
                ddlNoSame.SelectedValue = dt.Rows[0]["NoSame"].ToString();
                ddlNoJianDu.SelectedValue = dt.Rows[0]["NoJianDu"].ToString();
                rbtnIsShouHui.SelectedValue = dt.Rows[0]["IsShouHui"].ToString();
                if (rbtnIsShouHui.SelectedValue == "1")
                {
                    txtShouHuiReason.Text = dt.Rows[0]["ShouHuiReason"].ToString();
                    this.dvShouHuiReason.Visible = true;
                    this.txtShouHuiReason.Focus();
                } 
                rbtIsZhiXing.SelectedValue = dt.Rows[0]["IsZhiXing"].ToString();
                ddlNoBackMoney.SelectedValue = dt.Rows[0]["NoBackMoney"].ToString();
                txtWrongPut.Text = dt.Rows[0]["WrongPut"].ToString();
            } 
        }

        protected void rbtnIsShouHui_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.rbtnIsShouHui.SelectedValue == "1")
            {
                this.dvShouHuiReason.Visible = true;
                this.txtShouHuiReason.Focus();
            }
            else
            {
                this.dvShouHuiReason.Visible = false;
            }
        }

        protected void btn_submit_Click(object sender, EventArgs e)
        {
            SunScore sun = new SunScore();

            sun.HospitalId = hfhospitalid.Value;
            sun.SunYear = DateTime.Now.Year;
            if (DateTime.Now.Day > 10)
            {
                sun.SunMonth = DateTime.Now.Month;
            }
            else if (DateTime.Now.Month - 1 == 0)
            {
                sun.SunMonth = 12;
                sun.SunYear = DateTime.Now.Year - 1;
            }
            else
            {
                sun.SunMonth = DateTime.Now.Month - 1;
            }

            sun.IsShiGu = Convert.ToInt32(ddlIsShiGu.SelectedValue);
            sun.IsPeiHe = Convert.ToInt32(ddlIsPeiHe.SelectedValue);
            sun.NoSame = Convert.ToInt32(ddlNoSame.SelectedValue);
            sun.NoJianDu = Convert.ToInt32(ddlNoJianDu.SelectedValue);
            sun.IsShouHui = Convert.ToInt32(rbtnIsShouHui.SelectedValue);
            sun.isAllGuaWang = Convert.ToInt32(rbtisAllGuaWang.SelectedValue);
            sun.ShouHuiReason = txtShouHuiReason.Text.Trim();
            sun.IsZhiXing = Convert.ToInt32(rbtIsZhiXing.SelectedValue);
            sun.NoBackMoney = Convert.ToInt32(ddlNoBackMoney.SelectedValue);
            sun.WrongPut = string.IsNullOrEmpty(txtWrongPut.Text.Trim()) ? 0 : Convert.ToInt32(txtWrongPut.Text.Trim());

            try
            {
                int a = i.UpdateSunScore(sun);
                if (a == 1)
                {
                    PageInfo("积分填报成功！", "SunScorePutHospitalList.aspx");
                }
                else
                {
                    PageInfo("积分填报失败！", "SunScorePutHospitalList.aspx");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

    }
}